{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "b511404c",
   "metadata": {},
   "source": [
    "-----------\n",
    "* 2022-11-22 Week14\n",
    "* 内容：函数与模块\n",
    "* Python学习笔记\n",
    "----------"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "212139ef",
   "metadata": {},
   "source": [
    "# 1.函数的定义"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "0585c2fd",
   "metadata": {},
   "outputs": [],
   "source": [
    "def greet_user():\n",
    "    \"\"\"问候语函数\"\"\"\n",
    "    print(\"hello world\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "ea136d57",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "hello world\n"
     ]
    }
   ],
   "source": [
    "greet_user()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "366e1eb4",
   "metadata": {},
   "outputs": [],
   "source": [
    "def greet_user(username):\n",
    "    \"\"\"问候语函数\"\"\"\n",
    "    print(\"hello\",username)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "9a84ec75",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "hello Pretty\n"
     ]
    }
   ],
   "source": [
    "greet_user(\"Pretty\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "de425ac6",
   "metadata": {},
   "source": [
    "## 模块"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "405de2ac",
   "metadata": {},
   "outputs": [],
   "source": [
    "import nfu_crawl"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "14a8c4e0",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on function NFU_NEWS_URL in module nfu_crawl:\n",
      "\n",
      "NFU_NEWS_URL(分类, 页码)\n",
      "    可以快速查询广州南方学院新闻的页面链接\n",
      "    分类:[\"xxyw\",\"xydt\"\"tzgg\",\"ztb\",'gxdt']\n",
      "    页码:[113,106,37,27]\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(nfu_crawl.NFU_NEWS_URL)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "178e1de1",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "http://www.nfu.edu.cn/xydt/index0.htm\n",
      "http://www.nfu.edu.cn/xydt/index1.htm\n",
      "http://www.nfu.edu.cn/xydt/index2.htm\n",
      "http://www.nfu.edu.cn/xydt/index3.htm\n",
      "http://www.nfu.edu.cn/xydt/index4.htm\n",
      "http://www.nfu.edu.cn/xydt/index5.htm\n",
      "http://www.nfu.edu.cn/xydt/index6.htm\n",
      "http://www.nfu.edu.cn/xydt/index7.htm\n",
      "http://www.nfu.edu.cn/xydt/index8.htm\n",
      "http://www.nfu.edu.cn/xydt/index9.htm\n",
      "http://www.nfu.edu.cn/xydt/index10.htm\n",
      "http://www.nfu.edu.cn/xydt/index11.htm\n",
      "http://www.nfu.edu.cn/xydt/index12.htm\n",
      "http://www.nfu.edu.cn/xydt/index13.htm\n",
      "http://www.nfu.edu.cn/xydt/index14.htm\n",
      "http://www.nfu.edu.cn/xydt/index15.htm\n",
      "http://www.nfu.edu.cn/xydt/index16.htm\n",
      "http://www.nfu.edu.cn/xydt/index17.htm\n",
      "http://www.nfu.edu.cn/xydt/index18.htm\n",
      "http://www.nfu.edu.cn/xydt/index19.htm\n",
      "http://www.nfu.edu.cn/xydt/index20.htm\n",
      "http://www.nfu.edu.cn/xydt/index21.htm\n",
      "http://www.nfu.edu.cn/xydt/index22.htm\n",
      "http://www.nfu.edu.cn/xydt/index23.htm\n",
      "http://www.nfu.edu.cn/xydt/index24.htm\n",
      "http://www.nfu.edu.cn/xydt/index25.htm\n",
      "http://www.nfu.edu.cn/xydt/index26.htm\n",
      "http://www.nfu.edu.cn/xydt/index27.htm\n",
      "http://www.nfu.edu.cn/xydt/index28.htm\n",
      "http://www.nfu.edu.cn/xydt/index29.htm\n",
      "http://www.nfu.edu.cn/xydt/index30.htm\n",
      "http://www.nfu.edu.cn/xydt/index31.htm\n",
      "http://www.nfu.edu.cn/xydt/index32.htm\n",
      "http://www.nfu.edu.cn/xydt/index33.htm\n",
      "http://www.nfu.edu.cn/xydt/index34.htm\n",
      "http://www.nfu.edu.cn/xydt/index35.htm\n",
      "http://www.nfu.edu.cn/xydt/index36.htm\n",
      "http://www.nfu.edu.cn/xydt/index37.htm\n",
      "http://www.nfu.edu.cn/xydt/index38.htm\n",
      "http://www.nfu.edu.cn/xydt/index39.htm\n",
      "http://www.nfu.edu.cn/xydt/index40.htm\n",
      "http://www.nfu.edu.cn/xydt/index41.htm\n",
      "http://www.nfu.edu.cn/xydt/index42.htm\n",
      "http://www.nfu.edu.cn/xydt/index43.htm\n",
      "http://www.nfu.edu.cn/xydt/index44.htm\n",
      "http://www.nfu.edu.cn/xydt/index45.htm\n",
      "http://www.nfu.edu.cn/xydt/index46.htm\n",
      "http://www.nfu.edu.cn/xydt/index47.htm\n",
      "http://www.nfu.edu.cn/xydt/index48.htm\n",
      "http://www.nfu.edu.cn/xydt/index49.htm\n",
      "http://www.nfu.edu.cn/xydt/index50.htm\n",
      "http://www.nfu.edu.cn/xydt/index51.htm\n",
      "http://www.nfu.edu.cn/xydt/index52.htm\n",
      "http://www.nfu.edu.cn/xydt/index53.htm\n",
      "http://www.nfu.edu.cn/xydt/index54.htm\n",
      "http://www.nfu.edu.cn/xydt/index55.htm\n",
      "http://www.nfu.edu.cn/xydt/index56.htm\n",
      "http://www.nfu.edu.cn/xydt/index57.htm\n",
      "http://www.nfu.edu.cn/xydt/index58.htm\n",
      "http://www.nfu.edu.cn/xydt/index59.htm\n",
      "http://www.nfu.edu.cn/xydt/index60.htm\n",
      "http://www.nfu.edu.cn/xydt/index61.htm\n",
      "http://www.nfu.edu.cn/xydt/index62.htm\n",
      "http://www.nfu.edu.cn/xydt/index63.htm\n",
      "http://www.nfu.edu.cn/xydt/index64.htm\n",
      "http://www.nfu.edu.cn/xydt/index65.htm\n",
      "http://www.nfu.edu.cn/xydt/index66.htm\n",
      "http://www.nfu.edu.cn/xydt/index67.htm\n",
      "http://www.nfu.edu.cn/xydt/index68.htm\n",
      "http://www.nfu.edu.cn/xydt/index69.htm\n",
      "http://www.nfu.edu.cn/xydt/index70.htm\n",
      "http://www.nfu.edu.cn/xydt/index71.htm\n",
      "http://www.nfu.edu.cn/xydt/index72.htm\n",
      "http://www.nfu.edu.cn/xydt/index73.htm\n",
      "http://www.nfu.edu.cn/xydt/index74.htm\n",
      "http://www.nfu.edu.cn/xydt/index75.htm\n",
      "http://www.nfu.edu.cn/xydt/index76.htm\n",
      "http://www.nfu.edu.cn/xydt/index77.htm\n",
      "http://www.nfu.edu.cn/xydt/index78.htm\n",
      "http://www.nfu.edu.cn/xydt/index79.htm\n",
      "http://www.nfu.edu.cn/xydt/index80.htm\n",
      "http://www.nfu.edu.cn/xydt/index81.htm\n",
      "http://www.nfu.edu.cn/xydt/index82.htm\n",
      "http://www.nfu.edu.cn/xydt/index83.htm\n",
      "http://www.nfu.edu.cn/xydt/index84.htm\n",
      "http://www.nfu.edu.cn/xydt/index85.htm\n",
      "http://www.nfu.edu.cn/xydt/index86.htm\n",
      "http://www.nfu.edu.cn/xydt/index87.htm\n",
      "http://www.nfu.edu.cn/xydt/index88.htm\n",
      "http://www.nfu.edu.cn/xydt/index89.htm\n",
      "http://www.nfu.edu.cn/xydt/index90.htm\n",
      "http://www.nfu.edu.cn/xydt/index91.htm\n",
      "http://www.nfu.edu.cn/xydt/index92.htm\n",
      "http://www.nfu.edu.cn/xydt/index93.htm\n",
      "http://www.nfu.edu.cn/xydt/index94.htm\n",
      "http://www.nfu.edu.cn/xydt/index95.htm\n",
      "http://www.nfu.edu.cn/xydt/index96.htm\n",
      "http://www.nfu.edu.cn/xydt/index97.htm\n",
      "http://www.nfu.edu.cn/xydt/index98.htm\n",
      "http://www.nfu.edu.cn/xydt/index99.htm\n",
      "http://www.nfu.edu.cn/xydt/index100.htm\n",
      "http://www.nfu.edu.cn/xydt/index101.htm\n",
      "http://www.nfu.edu.cn/xydt/index102.htm\n",
      "http://www.nfu.edu.cn/xydt/index103.htm\n",
      "http://www.nfu.edu.cn/xydt/index104.htm\n",
      "http://www.nfu.edu.cn/xydt/index105.htm\n"
     ]
    }
   ],
   "source": [
    "nfu_crawl.NFU_NEWS_URL(\"xydt\",106)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "id": "5c241303",
   "metadata": {},
   "outputs": [],
   "source": [
    "#函数实践\n",
    "def NFU_NEWS_URL(分类,页码):\n",
    "    \"\"\"可以快速查询广州南方学院新闻的页面链接\n",
    "        分类:[\"xxyw\",\"xydt\"\"tzgg\",\"ztb\",'gxdt']\n",
    "        页码:[113,106,37,27]\n",
    "    \"\"\"\n",
    "    \n",
    "    for i in range(页码):\n",
    "        print(\"http://www.nfu.edu.cn/\"+分类+\"/index\"+str(i)+\".htm\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "id": "ba4178b9",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on function NFU_NEWS_URL in module __main__:\n",
      "\n",
      "NFU_NEWS_URL(分类, 页码)\n",
      "    可以快速查询广州南方学院新闻的页面链接\n",
      "    分类:[\"xxyw\",\"xydt\"\"tzgg\",\"ztb\",'gxdt']\n",
      "    页码:[113,106,37,27]\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(NFU_NEWS_URL)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "id": "0f06f1d8",
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "http://www.nfu.edu.cn/xydt/index0.htm\n",
      "http://www.nfu.edu.cn/xydt/index1.htm\n",
      "http://www.nfu.edu.cn/xydt/index2.htm\n",
      "http://www.nfu.edu.cn/xydt/index3.htm\n",
      "http://www.nfu.edu.cn/xydt/index4.htm\n",
      "http://www.nfu.edu.cn/xydt/index5.htm\n",
      "http://www.nfu.edu.cn/xydt/index6.htm\n",
      "http://www.nfu.edu.cn/xydt/index7.htm\n",
      "http://www.nfu.edu.cn/xydt/index8.htm\n",
      "http://www.nfu.edu.cn/xydt/index9.htm\n",
      "http://www.nfu.edu.cn/xydt/index10.htm\n",
      "http://www.nfu.edu.cn/xydt/index11.htm\n",
      "http://www.nfu.edu.cn/xydt/index12.htm\n",
      "http://www.nfu.edu.cn/xydt/index13.htm\n",
      "http://www.nfu.edu.cn/xydt/index14.htm\n",
      "http://www.nfu.edu.cn/xydt/index15.htm\n",
      "http://www.nfu.edu.cn/xydt/index16.htm\n",
      "http://www.nfu.edu.cn/xydt/index17.htm\n",
      "http://www.nfu.edu.cn/xydt/index18.htm\n",
      "http://www.nfu.edu.cn/xydt/index19.htm\n",
      "http://www.nfu.edu.cn/xydt/index20.htm\n",
      "http://www.nfu.edu.cn/xydt/index21.htm\n",
      "http://www.nfu.edu.cn/xydt/index22.htm\n",
      "http://www.nfu.edu.cn/xydt/index23.htm\n",
      "http://www.nfu.edu.cn/xydt/index24.htm\n",
      "http://www.nfu.edu.cn/xydt/index25.htm\n",
      "http://www.nfu.edu.cn/xydt/index26.htm\n",
      "http://www.nfu.edu.cn/xydt/index27.htm\n",
      "http://www.nfu.edu.cn/xydt/index28.htm\n",
      "http://www.nfu.edu.cn/xydt/index29.htm\n",
      "http://www.nfu.edu.cn/xydt/index30.htm\n",
      "http://www.nfu.edu.cn/xydt/index31.htm\n",
      "http://www.nfu.edu.cn/xydt/index32.htm\n",
      "http://www.nfu.edu.cn/xydt/index33.htm\n",
      "http://www.nfu.edu.cn/xydt/index34.htm\n",
      "http://www.nfu.edu.cn/xydt/index35.htm\n",
      "http://www.nfu.edu.cn/xydt/index36.htm\n",
      "http://www.nfu.edu.cn/xydt/index37.htm\n",
      "http://www.nfu.edu.cn/xydt/index38.htm\n",
      "http://www.nfu.edu.cn/xydt/index39.htm\n",
      "http://www.nfu.edu.cn/xydt/index40.htm\n",
      "http://www.nfu.edu.cn/xydt/index41.htm\n",
      "http://www.nfu.edu.cn/xydt/index42.htm\n",
      "http://www.nfu.edu.cn/xydt/index43.htm\n",
      "http://www.nfu.edu.cn/xydt/index44.htm\n",
      "http://www.nfu.edu.cn/xydt/index45.htm\n",
      "http://www.nfu.edu.cn/xydt/index46.htm\n",
      "http://www.nfu.edu.cn/xydt/index47.htm\n",
      "http://www.nfu.edu.cn/xydt/index48.htm\n",
      "http://www.nfu.edu.cn/xydt/index49.htm\n",
      "http://www.nfu.edu.cn/xydt/index50.htm\n",
      "http://www.nfu.edu.cn/xydt/index51.htm\n",
      "http://www.nfu.edu.cn/xydt/index52.htm\n",
      "http://www.nfu.edu.cn/xydt/index53.htm\n",
      "http://www.nfu.edu.cn/xydt/index54.htm\n",
      "http://www.nfu.edu.cn/xydt/index55.htm\n",
      "http://www.nfu.edu.cn/xydt/index56.htm\n",
      "http://www.nfu.edu.cn/xydt/index57.htm\n",
      "http://www.nfu.edu.cn/xydt/index58.htm\n",
      "http://www.nfu.edu.cn/xydt/index59.htm\n",
      "http://www.nfu.edu.cn/xydt/index60.htm\n",
      "http://www.nfu.edu.cn/xydt/index61.htm\n",
      "http://www.nfu.edu.cn/xydt/index62.htm\n",
      "http://www.nfu.edu.cn/xydt/index63.htm\n",
      "http://www.nfu.edu.cn/xydt/index64.htm\n",
      "http://www.nfu.edu.cn/xydt/index65.htm\n",
      "http://www.nfu.edu.cn/xydt/index66.htm\n",
      "http://www.nfu.edu.cn/xydt/index67.htm\n",
      "http://www.nfu.edu.cn/xydt/index68.htm\n",
      "http://www.nfu.edu.cn/xydt/index69.htm\n",
      "http://www.nfu.edu.cn/xydt/index70.htm\n",
      "http://www.nfu.edu.cn/xydt/index71.htm\n",
      "http://www.nfu.edu.cn/xydt/index72.htm\n",
      "http://www.nfu.edu.cn/xydt/index73.htm\n",
      "http://www.nfu.edu.cn/xydt/index74.htm\n",
      "http://www.nfu.edu.cn/xydt/index75.htm\n",
      "http://www.nfu.edu.cn/xydt/index76.htm\n",
      "http://www.nfu.edu.cn/xydt/index77.htm\n",
      "http://www.nfu.edu.cn/xydt/index78.htm\n",
      "http://www.nfu.edu.cn/xydt/index79.htm\n",
      "http://www.nfu.edu.cn/xydt/index80.htm\n",
      "http://www.nfu.edu.cn/xydt/index81.htm\n",
      "http://www.nfu.edu.cn/xydt/index82.htm\n",
      "http://www.nfu.edu.cn/xydt/index83.htm\n",
      "http://www.nfu.edu.cn/xydt/index84.htm\n",
      "http://www.nfu.edu.cn/xydt/index85.htm\n",
      "http://www.nfu.edu.cn/xydt/index86.htm\n",
      "http://www.nfu.edu.cn/xydt/index87.htm\n",
      "http://www.nfu.edu.cn/xydt/index88.htm\n",
      "http://www.nfu.edu.cn/xydt/index89.htm\n",
      "http://www.nfu.edu.cn/xydt/index90.htm\n",
      "http://www.nfu.edu.cn/xydt/index91.htm\n",
      "http://www.nfu.edu.cn/xydt/index92.htm\n",
      "http://www.nfu.edu.cn/xydt/index93.htm\n",
      "http://www.nfu.edu.cn/xydt/index94.htm\n",
      "http://www.nfu.edu.cn/xydt/index95.htm\n",
      "http://www.nfu.edu.cn/xydt/index96.htm\n",
      "http://www.nfu.edu.cn/xydt/index97.htm\n",
      "http://www.nfu.edu.cn/xydt/index98.htm\n",
      "http://www.nfu.edu.cn/xydt/index99.htm\n",
      "http://www.nfu.edu.cn/xydt/index100.htm\n",
      "http://www.nfu.edu.cn/xydt/index101.htm\n",
      "http://www.nfu.edu.cn/xydt/index102.htm\n",
      "http://www.nfu.edu.cn/xydt/index103.htm\n",
      "http://www.nfu.edu.cn/xydt/index104.htm\n",
      "http://www.nfu.edu.cn/xydt/index105.htm\n"
     ]
    }
   ],
   "source": [
    "NFU_NEWS_URL(\"xydt\",106)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "750642bb",
   "metadata": {},
   "source": [
    " # 1.关于实参和形参"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7a9d8675",
   "metadata": {},
   "source": [
    "*  positional argument (位置参数)\n",
    "*  keyword argument(关键字参数)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "3f68171e",
   "metadata": {},
   "outputs": [
    {
     "ename": "SyntaxError",
     "evalue": "positional argument follows keyword argument (1075781691.py, line 5)",
     "output_type": "error",
     "traceback": [
      "\u001b[0;36m  Input \u001b[0;32mIn [12]\u001b[0;36m\u001b[0m\n\u001b[0;31m    func_test(x=1,2)\u001b[0m\n\u001b[0m                   ^\u001b[0m\n\u001b[0;31mSyntaxError\u001b[0m\u001b[0;31m:\u001b[0m positional argument follows keyword argument\n"
     ]
    }
   ],
   "source": [
    "#eg1\n",
    "def func_test(x,y):\n",
    "    print(x)\n",
    "    print(y)\n",
    "func_test(x=1,2)#位置参数要在后边"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "ace2335c",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1\n",
      "2\n"
     ]
    }
   ],
   "source": [
    "#eg2\n",
    "def func_test(x,y):\n",
    "    print(x)\n",
    "    print(y)\n",
    "func_test(1,y=2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "931f895a",
   "metadata": {},
   "outputs": [
    {
     "ename": "SyntaxError",
     "evalue": "positional argument follows keyword argument (725090461.py, line 5)",
     "output_type": "error",
     "traceback": [
      "\u001b[0;36m  Input \u001b[0;32mIn [13]\u001b[0;36m\u001b[0m\n\u001b[0;31m    func_test(1,y=2,3)\u001b[0m\n\u001b[0m                     ^\u001b[0m\n\u001b[0;31mSyntaxError\u001b[0m\u001b[0;31m:\u001b[0m positional argument follows keyword argument\n"
     ]
    }
   ],
   "source": [
    "#eg3\n",
    "def func_test(x,y,z):\n",
    "    print(x)\n",
    "    print(y)\n",
    "func_test(1,y=2,3) #关键字参数要放最后"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "1651cd5d",
   "metadata": {},
   "outputs": [
    {
     "ename": "SyntaxError",
     "evalue": "invalid character '，' (U+FF0C) (485623660.py, line 5)",
     "output_type": "error",
     "traceback": [
      "\u001b[0;36m  Input \u001b[0;32mIn [16]\u001b[0;36m\u001b[0m\n\u001b[0;31m    func_test(1,3，y=2)\u001b[0m\n\u001b[0m                 ^\u001b[0m\n\u001b[0;31mSyntaxError\u001b[0m\u001b[0;31m:\u001b[0m invalid character '，' (U+FF0C)\n"
     ]
    }
   ],
   "source": [
    "#eg4\n",
    "def func_test(x,y,z):\n",
    "    print(x)\n",
    "    print(y)\n",
    "func_test(1,3，y=2)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ad17d6f6",
   "metadata": {},
   "source": [
    "## 默认函数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "4279c763",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "hello world|||hello world\n"
     ]
    }
   ],
   "source": [
    "print(\"hello world\",end='|||')\n",
    "print(\"hello world\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "592e4faa",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function print in module builtins:\n",
      "\n",
      "print(...)\n",
      "    print(value, ..., sep=' ', end='\\n', file=sys.stdout, flush=False)\n",
      "    \n",
      "    Prints the values to a stream, or to sys.stdout by default.\n",
      "    Optional keyword arguments:\n",
      "    file:  a file-like object (stream); defaults to the current sys.stdout.\n",
      "    sep:   string inserted between values, default a space.\n",
      "    end:   string appended after the last value, default a newline.\n",
      "    flush: whether to forcibly flush the stream.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(print)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "617f8c4e",
   "metadata": {},
   "source": [
    "## 函数的返回值\n",
    "* 函数返回的值被称为函数的返回值"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "aaccf657",
   "metadata": {},
   "source": [
    "* 对于计算机而言，函数必须有返回值 return (公理)\n",
    "* Python:返回值给了一个默认值（None）\n",
    ">1.返回值的第一种情况：返回函数过程的计算结果  \n",
    ">2.返回值的第二种情况：返回函数过程运算的过程  \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "id": "16685c5e",
   "metadata": {},
   "outputs": [],
   "source": [
    "def func(x):\n",
    "    \"\"\"计算y=2x\"\"\"\n",
    "    y=2*x\n",
    "    return y"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "id": "95ec9413",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "4\n"
     ]
    }
   ],
   "source": [
    "print(func(2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "66dc6c5e",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
